/**
 * Created by geqq on 2018/5/14 0937.
 */
var FundIndex = new Vue({
    el: '#fund-index',
    data: {
        datas: {
            'paginator':{},
            'billList': []
        },
        acctFundInfo: {},
        isShowBindAccount: false,
        isShowVerification: false,
        search: {
            pageNo: 1,
            pageSize: 20,
            startDate: '',
            endDate: ''
        },
        show: '',
        amount: '',
        bankCard:{
            bankNumber: '***********9576',
            bankName: '中国银行'
        }
    },
    methods: {
        getAcctFundInfo: function () {
            var _this = this;
            _this.setAjaxOptions('/getAcctFundInfo', null, function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    _this.acctFundInfo = result.data;
                } else {
                    console.log(result.errMsg);
                }
            });
            _this.doAjax();
        },
        getFundFlow: function () {
            var _this = this;
            _this.setAjaxOptions('/getFundFlow', _this.search, function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    _this.datas = result.data;
                    Vue.useLayerPage('laypage', _this.datas.paginator, _this.search);
                } else {
                    console.log(result.errMsg);
                }
            });
            _this.doAjax();
        },
        showBindAccount: function () {
            if (!this.isShowBindAccount) {
                this.isShowBindAccount = !this.isShowBindAccount;
            }

            Vue.useLayerForm();
        },
        showVerification: function () {
            if (!this.isShowVerification) {
                this.isShowVerification = !this.isShowVerification;
            }

            Vue.useLayerForm();
        },
        opendrawCash: function () {
            if (this.show == '') {
                this.show = 'extract';
            }

        },
        withdrawCash: function () {
            var _this = this;
            if (_this.amount > this.acctFundInfo.cashAmt || _this.amount.length==0 || _this.amount<=0) {
                console.log('无法提取余额');
                return;
            }
            _this.setAjaxOptions('/withdrawCash', {'amount': _this.amount}, function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    console.log('success');
                    this.getAcctFundInfo();
                    _this.show = '';
                } else {
                    console.log(result.errMsg);
                }
            });

            _this.doAjax();
        },
        goPrev: function () {
            this.show = '';
            this.amount = '';
        }
    },
    mixins: [AjaxMixin, StatusMixin, UserMixin],
    mounted: function () {
        Vue.useLayerElement();
        this.search.startDate = moment().subtract(6, 'days').format('YYYY-MM-DD'); // 6天前
        this.search.endDate = moment().format('YYYY-MM-DD'); // 当前天
        Vue.useLayerDate(['startDate', 'endDate'], this.search);
        this.getAcctFundInfo();
        this.getFundFlow();
        Vue.useLayerForm();
    },
    watch: {
        'search': {
            handler: function (val, oldVal) {
                this.getFundFlow();
            },
            deep: true
        },
        'amount': function (val, oldVal) {
            if (val > this.acctFundInfo.cashAmt) {

            }
        }
    }
});